package com.meida.module.bus.provider.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.util.TypeUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.mybatis.query.CriteriaUpdate;
import com.meida.common.security.OpenHelper;
import com.meida.common.security.OpenUser;
import com.meida.common.utils.DateUtils;
import com.meida.common.utils.FlymeUtils;
import com.meida.module.bus.client.entity.*;
import com.meida.module.bus.provider.api.service.SyncOAService;
import com.meida.module.bus.provider.api.service.SyncSrmService;
import com.meida.module.bus.provider.api.util.ApiConstants;
import com.meida.module.bus.provider.api.util.PmsApiUtil;
import com.meida.module.bus.provider.api.util.PmsOaUtil;
import com.meida.module.bus.provider.mapper.BusMaterialPackage100Mapper;
import com.meida.module.bus.provider.service.*;
import com.meida.module.bus.provider.utils.CommonUtil;
import com.meida.module.bus.provider.utils.LevelNoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 100分包接口实现类
 *
 * @author flyme
 * @date 2020-10-10
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusMaterialPackage100ServiceImpl extends BaseServiceImpl<BusMaterialPackage100Mapper, BusMaterialPackage100> implements BusMaterialPackage100Service {


    @Autowired
    BusMaterialPackage100Service busMaterialPackage100Service;

    @Autowired
    BusMaterialPackage200Service busMaterialPackage200Service;

    @Autowired
    BusVersionService busVersionService;

    @Autowired
    BusProjectService busProjectService;

    @Autowired
    BusMaterialService busMaterialService;

    @Autowired
    BusProjectSupplierService busProjectSupplierService;

    @Autowired
    BusReportService busReportService;

    @Autowired
    PmsOaUtil pmsOaUtil;

    @Autowired
    SyncSrmService syncSrmService;

    @Autowired
    LevelNoUtil levelNoUtil;

    @Autowired
    CommonUtil commonUtil;

    @Autowired
    SyncOAService syncOAService;

    @Autowired
    private PmsApiUtil pmsApiUtil;

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusMaterialPackage100 bmp, EntityMap extra) {
        Long projectId = TypeUtils.castToLong(bmp.getProjectId());
        BusProject busProject = busProjectService.getById(projectId);
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.failed("项目信息不存在");
        }
        Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
        if (state == 1) {
            return ResultBody.failed("项目已锁定");
        }
        return ResultBody.ok();
    }

    @Override
    public ResultBody beforeEdit(CriteriaUpdate<BusMaterialPackage100> cu, BusMaterialPackage100 busMaterialPackage100, EntityMap extra) {
        Long materialPackage100Id1 = busMaterialPackage100.getMaterialPackage100Id();
        BusMaterialPackage100 materialPackage100 = getById(materialPackage100Id1);
        BusProject busProject = busProjectService.getById(materialPackage100.getProjectId());
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.failed("项目信息不存在");
        }
        Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
        if (state == 1) {
            return ResultBody.failed("项目已锁定");
        }
        EntityMap requestMap = cu.getRequestMap();
        Long materialPackage100Id = busMaterialPackage100.getMaterialPackage100Id();
        BusMaterialPackage100 busMaterialPackage100Info = getById(materialPackage100Id);
        BigDecimal costQuantity100 = busMaterialPackage100Info.getCostQuantity100();
        BigDecimal supplierNum1 = requestMap.getBigDecimal("supplierNum1");
        BigDecimal supplierNum2 = requestMap.getBigDecimal("supplierNum2");
        BigDecimal supplierNum3 = requestMap.getBigDecimal("supplierNum3");
        BigDecimal supplierNum4 = requestMap.getBigDecimal("supplierNum4");
        BigDecimal supplierNum5 = requestMap.getBigDecimal("supplierNum5");
        BigDecimal supplierNum6 = requestMap.getBigDecimal("supplierNum6");
        BigDecimal supplierNum7 = requestMap.getBigDecimal("supplierNum7");
        BigDecimal supplierNum8 = requestMap.getBigDecimal("supplierNum8");
        BigDecimal supplierNum9 = requestMap.getBigDecimal("supplierNum9");
        BigDecimal supplierNum10 = requestMap.getBigDecimal("supplierNum10");
        BigDecimal totalSupplierNum = supplierNum1.add(supplierNum2).add(supplierNum3).add(supplierNum4).add(supplierNum5).add(supplierNum6).add(supplierNum7).add(supplierNum8).add(supplierNum9).add(supplierNum10);
        if (costQuantity100.compareTo(totalSupplierNum) == -1) {
            return ResultBody.failed("包商合同总量应小于等于100版预算成本工程量");
        }
        return super.beforeEdit(cu, busMaterialPackage100, extra);
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusMaterialPackage100> cq, BusMaterialPackage100 bmp, EntityMap requestMap) {
        cq.addSelect(BusMaterialPackage100.class, "*");
        cq.addSelect(BusProject.class, "projectName", "projectCode");
        cq.addSelect(BusMaterial.class, "unitBillQuantity100", "beforeMarkQuantity", "convertBillQuantity100", "planPurchaseCount", "convertPurchaseCount", "installPrice", "syntheticalPrice", "installPrice1", "syntheticalPrice1", "installPrice2", "syntheticalPrice2", "measurementUnit");
        cq.eq("bmp.projectId", requestMap.get("projectId"));
        //项目代码
        cq.like(BusProject.class, "projectCode", requestMap.get("projectCode"));
        //项目名称
        cq.like(BusProject.class, "projectName", requestMap.get("projectName"));
        //专业包代码
        cq.like(BusMaterialPackage100.class, "majorCode", requestMap.get("majorCode"));
        //专业包名称
        cq.like(BusMaterialPackage100.class, "majorName", requestMap.get("majorName"));
        //工程包代码
        cq.like(BusMaterialPackage100.class, "packageNo", requestMap.get("packageNo"));
        //工程包名称
        cq.like(BusMaterialPackage100.class, "packageName", requestMap.get("packageName"));
        //服务WBS
        cq.like(BusMaterialPackage100.class, "serviceWbsCode", requestMap.get("serviceWbsCode"));
        //服务代码
        cq.like(BusMaterialPackage100.class, "serviceCode", requestMap.get("serviceCode"));
        //科目名称
        cq.like(BusMaterialPackage100.class, "subjectName", requestMap.get("subjectName"));
        //区域
        cq.like(BusMaterialPackage100.class, "materialArea", requestMap.get("materialArea"));
        //系统
        cq.like(BusMaterialPackage100.class, "materialUse", requestMap.get("materialUse"));
        //层级号
        cq.like(BusMaterialPackage100.class, "levelNo", requestMap.get("levelNo"));
        cq.eq("bmp.projectId", requestMap.get("projectId"));
        cq.eq("planType", requestMap.get("planType"));
        cq.eq("versionStatus", requestMap.get("versionStatus"));
        Boolean isGroup = requestMap.getBoolean("isGroup");
        //100分包列表数据
        if (isGroup) {
            cq.groupBy("projectId", "packageNo", "majorCode");
        } else {
            //100分包详情列表
            cq.eq("bmp.packageNo", requestMap.get("packageNo"));
            cq.eq("bmp.majorCode", requestMap.get("majorCode"));
            Boolean isReport = requestMap.getBoolean("isReport");
            if (isReport) {
                cq.eq("bmp.parentId", 0);
            }
        }
        cq.eq("bmp.versionId", requestMap.get("versionId"));
        cq.eq(BusMaterialPackage100.class, "status", 1);
        cq.createJoin(BusMaterial.class).setJoinField("materialId").setMainField("materialId");
        cq.createJoin(BusProject.class).setJoinField("projectId").setMainField("projectId");
        cq.orderByAsc("bmp.levelNo");
//        cq.orderByDesc("bmp.createTime");
        return ResultBody.ok();
    }

    @Override
    public BusMaterialPackage100 getlevelNo(String levelNo) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("levelNo", levelNo);
        return getOne(cq);
    }

    @Override
    public List<Long> getinitPlanIds(Long projectId) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery<BusMaterialPackage100>(BusMaterialPackage100.class);
        cq.select("materialPackage100Id");
        cq.eq("status", 0);
        return selectLongs(cq);
    }

    @Override
    @Transactional
    public ResultBody copyAndUpdate(Map map) {
        Long projectId = TypeUtils.castToLong(map.get("projectId"));
        BusProject busProject = busProjectService.getById(projectId);
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.failed("项目信息不存在");
        }
        Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
        if (state == 1) {
            return ResultBody.failed("项目已锁定");
        }
        Integer archive200packge = FlymeUtils.getInteger(busProject.getArchive200packge(), 0);
        if (archive200packge == 1) {
            return ResultBody.failed("该项目已转存200");
        }
        String copyDataStr = (String) map.get("copyDataStr");
        if (FlymeUtils.isEmpty(copyDataStr)) {
            return ResultBody.failed("没有要提交的数据");
        }
        Integer type = TypeUtils.castToInt(map.get("type"));
        BusVersion newBusVersion = busVersionService.getNewBusVersion(projectId, 2, type);
        Long versionId = newBusVersion.getVersionId();
        busVersionService.save(newBusVersion);
        List<BusMaterialPackage100> busMaterialPackage100List = JSON.parseArray(copyDataStr, BusMaterialPackage100.class);
        List<BusMaterial> busMaterialList = new ArrayList<>();
        for (BusMaterialPackage100 busMaterialPackage100 : busMaterialPackage100List) {
            Long id = IdWorker.getId();
            Long materialId = busMaterialPackage100.getMaterialId();
            Long parentId = busMaterialPackage100.getParentId();
            busMaterialPackage100.setMaterialPackage100Id(id);
            busMaterialPackage100.setMaterialId(id);
            if (parentId.longValue() == 0L) {
                busMaterialPackage100.setParentId(materialId);
            } else {
                busMaterialPackage100.setParentId(parentId);
            }
            Long parentId1 = busMaterialPackage100.getParentId();
            String packageNo = busMaterialPackage100.getPackageNo();
            String levelNo = busMaterialPackage100.getLevelNo();
            String redisKey = "package100_" + parentId1;
            levelNo = levelNoUtil.getLevelNo(redisKey, packageNo, levelNo);
            busMaterialPackage100.setLevelNo(levelNo);
            busMaterialPackage100.setPlanType(type);
            busMaterialPackage100.setVersionId(versionId);
            busMaterialPackage100.setCreateTime(DateUtils.getNowDateTime());
            busMaterialPackage100.setUpdateTime(null);
            busMaterialPackage100.setVersionStatus(0);
            busMaterialPackage100.setApplayStatus(0);
            BusMaterial busMaterial = busMaterialService.getById(materialId);
            BusMaterial busMaterial1 = new BusMaterial();
            BeanUtils.copyProperties(busMaterial, busMaterial1);
            busMaterial1.setMaterialId(id);
            busMaterial1.setParentId(parentId1);
            busMaterial1.setCreateTime(DateUtils.getNowDateTime());
            busMaterial1.setUpdateTime(null);
            busMaterialList.add(busMaterial1);
        }
        if (busMaterialPackage100List.size() > 0) {
            busMaterialPackage100Service.saveBatch(busMaterialPackage100List);
            busMaterialService.saveBatch(busMaterialList);
            busProject.setVersionpackageId(versionId);
            busProjectService.updateById(busProject);
        }
        return ResultBody.ok();
    }

    @Override
    public Boolean updateApplayStatus(Long projectId, String packageNo, String majorCode, Integer planType, Integer applayStatus) {
        CriteriaUpdate<BusMaterialPackage100> cu = new CriteriaUpdate<>();
        cu.eq("projectId", projectId);
        cu.eq("packageNo", packageNo);
        cu.eq("majorCode", majorCode);
        cu.eq("planType", planType);
        cu.eq("versionStatus", 0);
        cu.set("applayStatus", applayStatus);
        return update(cu);
    }

    @Override
    @Transactional
    public ResultBody subArchive200OaCheck(Map map) {
        String userName = OpenHelper.getUserName();
        Long projectId = TypeUtils.castToLong(map.get("projectId"));
        BusProject busProject = busProjectService.getById(projectId);
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.failed("项目信息不存在");
        }
        Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
        if (state == 1) {
            return ResultBody.failed("项目已锁定");
        }
        Integer archive200packge = FlymeUtils.getInteger(busProject.getArchive200packge(), 0);
        if (archive200packge == 1) {
            return ResultBody.failed("该项目已转存200");
        }
        int i = totalByProject(projectId);
        if (i <= 0) {
            return ResultBody.failed("该项目无需转存,未有分包信息");
        }
        int j = totalByProjectAndVersionStatus(projectId, 0);
        if (j > 0) {
            return ResultBody.failed("该项目有数据未合并到根节点,需要提交合并数据");
        }
        //按分组校验是否编辑供应商，是否填写包商量
        List<BusMaterialPackage100> busMaterialPackage100List = getByGroup3Field(projectId);
        for (BusMaterialPackage100 busMaterialPackage100 : busMaterialPackage100List) {
            String packageNo = busMaterialPackage100.getPackageNo();
            String majorCode = busMaterialPackage100.getMajorCode();
            Map<String, Object> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("packageNo", packageNo);
            params.put("majorCode", majorCode);
            List<EntityMap> supplierIdList = busProjectSupplierService.getBusProjectSupplierIds(params);
            if (supplierIdList.size() <= 0) {
                return ResultBody.failed("该项目暂不能转存200版,工程包代码(" + packageNo + "),(专业代码" + majorCode + "),未编辑分包商信息");
            }
        }
        int approval = syncOAService.approval(map, "/approvl/bmpDetail", userName, ApiConstants.BUSINESS_APPROVAL_FB_100, projectId.toString());
        if (ApiConstants.APPROVAL_SUCCESS == approval) {
            return ResultBody.ok("操作成功");
        }
        return ResultBody.ok("操作失败");
    }

    /**
     * oA审批操作----转存200操作
     *
     * @param projectId  项目Id
     * @param checkState 审核状态
     * @return
     */
    @Override
    @Transactional
    public ResultBody goArchive200(Long projectId, Integer checkState) {
        //审批驳回
        if (checkState == ApiConstants.APPROVAL_REJECT) {
            ResultBody resultBody = busProjectService.updateProjectStus(projectId, 0);
            resultBody.setMsg("审批驳回,项目状态已更为正常");
            return resultBody;
        }
        //审批通过
        if (checkState == ApiConstants.APPROVAL_SUCCESS) {
            BusVersion busVersion = init200Version(projectId);
            busVersionService.save(busVersion);
            Long versionId = busVersion.getVersionId();
            BusProject busProject = busProjectService.getById(projectId);
            List<BusMaterialPackage200> busMaterialPackage200List = new ArrayList<>();
            List<BusReport> busReportList = new ArrayList<>();
            List<BusMaterial> busMaterialList = new ArrayList<>();
            //按分组校验是否编辑供应商，是否填写包商量
            List<BusMaterialPackage100> busMaterialPackage100List = getByGroup3Field(projectId);
            for (BusMaterialPackage100 busMaterialPackage100 : busMaterialPackage100List) {
                Long materialId = busMaterialPackage100.getMaterialId();
                BusMaterial busMaterial = busMaterialService.getById(materialId);
                String packageNo = busMaterialPackage100.getPackageNo();
                String majorCode = busMaterialPackage100.getMajorCode();
                HashMap<String, Object> params = Maps.newHashMap();
                params.put("projectId", projectId);
                params.put("packageNo", packageNo);
                params.put("majorCode", majorCode);
                BigDecimal totalCostQuantity100 = busMaterialPackage100.getCostQuantity100();
                BusMaterialPackage200 busMaterialPackage200 = new BusMaterialPackage200();
                long id = IdWorker.getId();
                BeanUtils.copyProperties(busMaterialPackage100, busMaterialPackage200);
                busMaterialPackage200.setMaterialPackage100Id(id);
                busMaterialPackage200.setMaterialId(id);
                busMaterialPackage200.setParentId(0L);
                busMaterialPackage200.setStatus("2");
                busMaterialPackage200.setCostQuantity100(totalCostQuantity100);
                busMaterialPackage200.setCostQuantity200(totalCostQuantity100);
                busMaterialPackage200.setCreateTime(DateUtils.getNowDateTime());
                busMaterialPackage200.setVersionId(versionId);
                busMaterialPackage200.setApplayStatus(null);
                // 关联100计划ID,保持数据连贯，SRM获取的合同能回溯数据源。
                busMaterialPackage200.setPackagePlan100Id(busMaterialPackage100.getMaterialPackage100Id());
                busMaterialPackage200List.add(busMaterialPackage200);
                busMaterial.setMaterialId(id);
                //预算成本合价_未税_合价_主材费
                BigDecimal mainPrice = FlymeUtils.getBigDecimal(busMaterial.getMainPrice(), "0");
                BigDecimal mainAmount = mainPrice.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setMainAmount(mainAmount);
                //预算成本合价_未税_合价_安装费
                BigDecimal installPrice = FlymeUtils.getBigDecimal(busMaterial.getInstallPrice(), "0");
                BigDecimal installAmount = installPrice.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setInstallAmount(installAmount);
                //预算成本合价_未税_合价_合计
                BigDecimal syntheticalAmount = mainAmount.add(installAmount);
                busMaterial.setSyntheticalAmount(syntheticalAmount);
                //预估总产值_有合同价_合价_主材价
                BigDecimal mainPrice1 = FlymeUtils.getBigDecimal(busMaterial.getMainPrice1(), "0");
                BigDecimal mainsumPrice1 = mainPrice1.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setMainsumPrice1(mainsumPrice1);
                //预估总产值_有合同价_合价_安装价
                BigDecimal installPrice1 = FlymeUtils.getBigDecimal(busMaterial.getInstallPrice1(), "0");
                BigDecimal installsumPrice1 = installPrice1.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setInstallsumPrice1(installsumPrice1);
                //预估总产值_有合同价_合价_合计
                BigDecimal contractsumSyntheticalPrice1 = mainsumPrice1.add(installsumPrice1);
                busMaterial.setContractsumSyntheticalPrice1(contractsumSyntheticalPrice1);
                //预估总产值_拟合同价_合价_主材价
                BigDecimal mainPrice2 = FlymeUtils.getBigDecimal(busMaterial.getMainPrice2(), "0");
                BigDecimal mainsumPrice2 = mainPrice2.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setMainsumPrice2(mainsumPrice2);
                //预估总产值_拟合同价_合价_安装价
                BigDecimal installPrice2 = FlymeUtils.getBigDecimal(busMaterial.getInstallPrice2(), "0");
                BigDecimal installsumPrice2 = installPrice2.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setInstallsumPrice2(installsumPrice2);
                //预估总产值_拟合同价_合价_合计
                BigDecimal contractsumSyntheticalPrice2 = mainsumPrice2.add(installsumPrice2);
                busMaterial.setContractsumSyntheticalPrice2(contractsumSyntheticalPrice2);
                //预估总产值_合同价_合价_主材价
                BigDecimal mainPrice3 = FlymeUtils.getBigDecimal(busMaterial.getMainPrice3(), "0");
                BigDecimal mainsumPrice3 = mainPrice3.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setMainsumPrice3(mainsumPrice3);
                //预估总产值_合同价_合价_安装价
                BigDecimal installPrice3 = FlymeUtils.getBigDecimal(busMaterial.getInstallPrice3(), "0");
                BigDecimal installsumPrice3 = installPrice3.multiply(totalCostQuantity100).setScale(10, BigDecimal.ROUND_DOWN);
                busMaterial.setInstallsumPrice3(installsumPrice3);
                //预估总产值_合同价_合价_合计
                BigDecimal contractsumSyntheticalPrice3 = mainsumPrice3.add(installsumPrice3);
                busMaterial.setContractsumSyntheticalPrice3(contractsumSyntheticalPrice3);
                busMaterialList.add(busMaterial);
                List<BusReport> reportList = busReportService.selectBusReportList(params);
                for (BusReport busReport : reportList) {
                    busReport.setReportType(2);
                    busReport.setMaterialId(id);
                }
                busReportList.addAll(reportList);
            }
            if (busMaterialPackage200List.size() > 0) {
                boolean save = busMaterialPackage200Service.saveBatch(busMaterialPackage200List);
                boolean b = busMaterialService.saveBatch(busMaterialList);
                busProject.setArchive200packge(1);
                busProject.setVersionpackageId(versionId);
                busProjectService.updateById(busProject);
                if (busReportList.size() > 0) {
                    busReportService.updateBatchById(busReportList);
                }
                if (save && b) {
                    return ResultBody.ok("审批通过,转存成功");
                }
            }
        }
        return ResultBody.failed("转存失败");
    }

    @Override
    public ResultBody subMerge100OaCheck(Map map) {
        Long projectId = FlymeUtils.getLong(map.get("projectId"));
        BusProject busProject = busProjectService.getById(projectId);
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.failed("项目信息不存在");
        }
        Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
        if (state == 1) {
            return ResultBody.failed("项目已锁定");
        }
        String userName = OpenHelper.getUserName();
        Integer type = TypeUtils.castToInt(map.get("type"));
        String packageNo = TypeUtils.castToString(map.get("packageNo"));
        String majorCode = TypeUtils.castToString(map.get("majorCode"));
        // 设定请求MAP
        pmsApiUtil.setPlanPackageDataToReqMap(map, projectId, packageNo, majorCode, type, type == 1 ? ApiConstants.ENGINEER_APPROVAL_FB_100_UPD : ApiConstants.ENGINEER_APPROVAL_FB_100_ADD);
        updateApplayStatus(projectId, packageNo, majorCode, type, 1);
        int approvalResult = 0;
        if (type == 1) {
            approvalResult = syncOAService.approval(map, "/approvl/bmp100UpdateDetail", userName, ApiConstants.ENGINEER_APPROVAL_FB_100_UPD, projectId.toString());

        }
        if (type == 2) {
            approvalResult = syncOAService.approval(map, "/approvl/bmp100AddDetail", userName, ApiConstants.ENGINEER_APPROVAL_FB_100_ADD, projectId.toString());

        }
        if (ApiConstants.APPROVAL_SUCCESS == approvalResult) {
            return ResultBody.ok("OA审批提交成功");
        } else {
            updateApplayStatus(projectId, packageNo, majorCode, type, 0);
        }
        return ResultBody.ok();

    }

    @Override
    public ResultBody goMerge100(Long projectId, String packageNo, String majorCode, String userName) throws Exception {
        Boolean b = pmsOaUtil.updateMaterialBaseForPackage(projectId, majorCode, packageNo, ApiConstants.VER_100, userName);
        if (b) {
            List<BusMaterialPackage100> busMaterialPackage100List = selectBusMaterialPackage100List(projectId, majorCode, packageNo);
            for (BusMaterialPackage100 busMaterialPackage100 : busMaterialPackage100List) {
                busMaterialPackage100.setVersionStatus(1);
                busMaterialPackage100.setApplayStatus(2);
            }
            if (busMaterialPackage100List.size() > 0) {
                updateBatchById(busMaterialPackage100List);
            }
            return ResultBody.ok("合并子节点成功");
        }
        return ResultBody.failed("合并子节点失败");
    }

    @Override
    public List<EntityMap> selectPackage100Details(Map map) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect(BusMaterialPackage100.class, "*");
        cq.addSelect(BusMaterial.class, "contractBillQuantity", "beforeMarkQuantity", "installPrice", "syntheticalPrice", "installPrice1", "syntheticalPrice1", "installPrice2", "syntheticalPrice2", "measurementUnit");
        cq.addSelect(BusProject.class, "projectCode", "projectName");
        cq.eq("bmp.projectId", map.get("projectId"));
        cq.eq("bmp.packageNo", map.get("packageNo"));
        cq.eq("bmp.majorCode", map.get("majorCode"));
        cq.like("levelNo", map.get("levelNo"));
        cq.like("serviceWbsCode", map.get("serviceWbsCode"));
        cq.like("serviceCode", map.get("serviceCode"));
        cq.like("subjectName", map.get("subjectName"));
        cq.like("materialArea", map.get("materialArea"));//系统
        cq.like("materialUse", map.get("materialUse"));
//        cq.orderByAsc("bmp.createTime");
        cq.orderByAsc("bmp.levelNo");
        cq.createJoin(BusProject.class).setMainField("projectId").setJoinField("projectId");
        cq.createJoin(BusMaterial.class).setMainField("materialPackage100Id").setJoinField("materialId");
        return selectEntityMap(cq);
    }

    @Override
    public List<EntityMap> selectPackage100RootDetails(Map map) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect(BusMaterialPackage100.class, "*");
        cq.addSelect(BusMaterial.class, "contractBillQuantity", "beforeMarkQuantity", "installPrice", "syntheticalPrice", "installPrice1", "syntheticalPrice1", "installPrice2", "syntheticalPrice2");
        cq.addSelect(BusProject.class, "projectCode", "projectName");
        cq.eq("bmp.projectId", map.get("projectId"));
        cq.eq("bmp.packageNo", map.get("packageNo"));
        cq.eq("bmp.majorCode", map.get("majorCode"));
        cq.eq("bmp.parentId", 0);
        cq.orderByAsc("bmp.createTime");
        cq.createJoin(BusProject.class).setMainField("projectId").setJoinField("projectId");
        cq.createJoin(BusMaterial.class).setMainField("materialPackage100Id").setJoinField("materialId");
        return selectEntityMap(cq);
    }

    @Override
    public List<BusMaterialPackage100> selectPackage100DetailData(Map map) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect(BusMaterialPackage100.class, "*");
        cq.eq("projectId", map.get("projectId"));
        cq.eq("packageNo", map.get("packageNo"));
        cq.eq("majorCode", map.get("majorCode"));
        return list(cq);
    }

    @Override
    public ResultBody importOnUpdateBusMaterialPackage100Data(MultipartFile file, Map params) {
        try {
            Long projectId = TypeUtils.castToLong(params.get("projectId"));
            BusProject busProject = busProjectService.getById(projectId);
            if (FlymeUtils.isEmpty(busProject)) {
                return ResultBody.failed("项目信息不存在");
            }
            Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
            if (state == 1) {
                return ResultBody.failed("项目已锁定");
            }
            List<BusMaterialPackage100> busMaterialPackage100List = new ArrayList<>();
            ImportParams importParams = new ImportParams();
            importParams.setTitleRows(1);
            List<Map<Object, Object>> ExcelList = ExcelImportUtil.importExcel(file.getInputStream(), Map.class, importParams);
            System.out.println(ExcelList.size());
            for (Map<Object, Object> objectMap : ExcelList) {
                Long materialPackage100Id = TypeUtils.castToLong(objectMap.get("分包Id"));
                BusMaterialPackage100 materialPackage100 = getById(materialPackage100Id);
                if (FlymeUtils.isNotEmpty(materialPackage100)) {
                    BigDecimal supplierNum1 = TypeUtils.castToBigDecimal(objectMap.get("包商1合同量"));
                    BigDecimal supplierNum2 = TypeUtils.castToBigDecimal(objectMap.get("包商2合同量"));
                    BigDecimal supplierNum3 = TypeUtils.castToBigDecimal(objectMap.get("包商3合同量"));
                    BigDecimal supplierNum4 = TypeUtils.castToBigDecimal(objectMap.get("包商4合同量"));
                    BigDecimal supplierNum5 = TypeUtils.castToBigDecimal(objectMap.get("包商5合同量"));
                    BigDecimal supplierNum6 = TypeUtils.castToBigDecimal(objectMap.get("包商6合同量"));
                    BigDecimal supplierNum7 = TypeUtils.castToBigDecimal(objectMap.get("包商7合同量"));
                    BigDecimal supplierNum8 = TypeUtils.castToBigDecimal(objectMap.get("包商8合同量"));
                    BigDecimal supplierNum9 = TypeUtils.castToBigDecimal(objectMap.get("包商9合同量"));
                    BigDecimal supplierNum10 = TypeUtils.castToBigDecimal(objectMap.get("包商10合同量"));
                    materialPackage100.setSupplierNum1(supplierNum1);
                    materialPackage100.setSupplierNum2(supplierNum2);
                    materialPackage100.setSupplierNum3(supplierNum3);
                    materialPackage100.setSupplierNum4(supplierNum4);
                    materialPackage100.setSupplierNum5(supplierNum5);
                    materialPackage100.setSupplierNum6(supplierNum6);
                    materialPackage100.setSupplierNum7(supplierNum7);
                    materialPackage100.setSupplierNum8(supplierNum8);
                    materialPackage100.setSupplierNum9(supplierNum9);
                    materialPackage100.setSupplierNum10(supplierNum10);
                    busMaterialPackage100List.add(materialPackage100);
                }
            }
            if (busMaterialPackage100List.size() > 0) {
                busMaterialPackage100Service.updateBatchById(busMaterialPackage100List);
                return ResultBody.ok("导入成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultBody.failed("导入失败");
    }

    @Override
    @Transactional
    public ResultBody importOnAddBusMaterialPackage100Data(MultipartFile file, Map params) {
        try {
            Integer type = TypeUtils.castToInt(params.get("type"));
            Long projectId = TypeUtils.castToLong(params.get("projectId"));
            BusProject busProject = busProjectService.getById(projectId);
            if (FlymeUtils.isEmpty(busProject)) {
                return ResultBody.failed("项目信息不存在");
            }
            Integer state = FlymeUtils.getInteger(busProject.getState(), 0);
            if (state == 1) {
                return ResultBody.failed("项目已锁定");
            }
            Integer archive200packge = FlymeUtils.getInteger(busProject.getArchive200packge(), 0);
            if (archive200packge == 1) {
                return ResultBody.failed("该项目已转存200");
            }
            String majorCode = (String) params.get("majorCode");
            String majorName = (String) params.get("majorName");
            String packageName = (String) params.get("packageName");
            String packageNo = (String) params.get("packageNo");
            List<BusMaterialPackage100> busMaterialPackage100List = new ArrayList<>();
            List<BusMaterial> busMaterialList = new ArrayList<>();
            ImportParams importParams = new ImportParams();
            importParams.setTitleRows(1);
            List<Map<Object, Object>> ExcelList = ExcelImportUtil.importExcel(file.getInputStream(), Map.class, importParams);
            if (commonUtil.ckLevelNo(projectId, ApiConstants.FB_PLANDATA_100, ExcelList)) {
                return ResultBody.failed("存在重复的层级号");
            }
            BusVersion busVersion = busVersionService.getNewBusVersion(projectId, 2, type);
            busVersionService.save(busVersion);
            ResultBody resultBody = pmsApiUtil.chkImpExcelContentForPlanData(ExcelList, ApiConstants.FB_PLANDATA);
            if (!resultBody.isOk()) {
                return resultBody;
            }
            for (Map<Object, Object> objectMap : ExcelList) {
                String isAddStr = TypeUtils.castToString(objectMap.get("是否新增"));
                isAddStr = FlymeUtils.getString(isAddStr, "是");
                if ("是".equals(isAddStr)) {
                    if (FlymeUtils.isNotEmpty(busProject)) {
                        Long materialPackage100Id = TypeUtils.castToLong(objectMap.get("分包Id"));
                        String serviceCode = TypeUtils.castToString(objectMap.get("服务代码"));
                        String serviceWbsCode = TypeUtils.castToString(objectMap.get("服务WBS代码"));
                        String subjectName = TypeUtils.castToString(objectMap.get("科目名称"));
                        String levelNo = TypeUtils.castToString(objectMap.get("层级号"));
                        String packageDesc = TypeUtils.castToString(objectMap.get("分承包发包项目描述"));
                        String contractDesc = TypeUtils.castToString(objectMap.get("对外合同描述"));
                        String materialArea = TypeUtils.castToString(objectMap.get("区域"));
                        String materialUse = TypeUtils.castToString(objectMap.get("系统"));
                        String measurementUnit = TypeUtils.castToString(objectMap.get("计量单位"));
                        BigDecimal costQuantity100 = TypeUtils.castToBigDecimal(objectMap.get("100预算成本工程量"));
                        BigDecimal beforeMarkQuantity = TypeUtils.castToBigDecimal(objectMap.get("标前工程量"));
                        BigDecimal unitBillQuantity100 = TypeUtils.castToBigDecimal(objectMap.get("100计量单位工程量合计"));
                        BigDecimal convertBillQuantity100 = TypeUtils.castToBigDecimal(objectMap.get("100换算单位工程量合计"));
                        BigDecimal supplierNum1 = TypeUtils.castToBigDecimal(objectMap.get("包商1合同量"));
                        BigDecimal supplierNum2 = TypeUtils.castToBigDecimal(objectMap.get("包商2合同量"));
                        BigDecimal supplierNum3 = TypeUtils.castToBigDecimal(objectMap.get("包商3合同量"));
                        BigDecimal supplierNum4 = TypeUtils.castToBigDecimal(objectMap.get("包商4合同量"));
                        BigDecimal supplierNum5 = TypeUtils.castToBigDecimal(objectMap.get("包商5合同量"));
                        BigDecimal supplierNum6 = TypeUtils.castToBigDecimal(objectMap.get("包商6合同量"));
                        BigDecimal supplierNum7 = TypeUtils.castToBigDecimal(objectMap.get("包商7合同量"));
                        BigDecimal supplierNum8 = TypeUtils.castToBigDecimal(objectMap.get("包商8合同量"));
                        BigDecimal supplierNum9 = TypeUtils.castToBigDecimal(objectMap.get("包商9合同量"));
                        BigDecimal supplierNum10 = TypeUtils.castToBigDecimal(objectMap.get("包商10合同量"));
                        BigDecimal installPrice = TypeUtils.castToBigDecimal(objectMap.get("预算成本单价（未税）_单价_安装价"));
                        BigDecimal syntheticalPrice = TypeUtils.castToBigDecimal(objectMap.get("预算成本单价（未税）_单价_综合单价"));
                        BigDecimal installPrice1 = TypeUtils.castToBigDecimal(objectMap.get("对外合同单价_有合同单价_安装价"));
                        BigDecimal syntheticalPrice1 = TypeUtils.castToBigDecimal(objectMap.get("对外合同单价_有合同单价_综合单价"));
                        BigDecimal installPrice2 = TypeUtils.castToBigDecimal(objectMap.get("对外合同单价_拟合同单价_安装价"));
                        BigDecimal syntheticalPrice2 = TypeUtils.castToBigDecimal(objectMap.get("对外合同单价_拟合同单价_综合单价"));
                        BusMaterial busMaterial = new BusMaterial();
                        long materialId = IdWorker.getId();
                        busMaterial.setMaterialId(materialId);
                        busMaterial.setProjectId(projectId);
                        busMaterial.setMeasurementUnit(measurementUnit);
                        busMaterial.setUnitBillQuantity100(unitBillQuantity100);
                        busMaterial.setConvertBillQuantity100(convertBillQuantity100);
                        busMaterial.setInstallPrice(installPrice);
                        busMaterial.setInstallPrice1(installPrice1);
                        busMaterial.setInstallPrice2(installPrice2);
                        busMaterial.setSyntheticalPrice(syntheticalPrice);
                        busMaterial.setSyntheticalPrice1(syntheticalPrice1);
                        busMaterial.setSyntheticalPrice2(syntheticalPrice2);
                        busMaterial.setBeforeMarkQuantity(beforeMarkQuantity);
                        BusMaterialPackage100 busMaterialPackage100 = new BusMaterialPackage100();
                        busMaterialPackage100.setMaterialPackage100Id(materialId);
                        busMaterialPackage100.setProjectId(projectId);
                        busMaterialPackage100.setMaterialId(materialId);
                        busMaterialPackage100.setApplayStatus(0);
                        if (FlymeUtils.isEmpty(materialPackage100Id)) {
                            busMaterialPackage100.setParentId(0L);
                        } else {
                            BusMaterialPackage100 materialPackage100 = getById(materialPackage100Id);
                            Long parentId = materialPackage100.getParentId();
                            if (parentId.longValue() == 0L) {
                                busMaterialPackage100.setParentId(materialPackage100Id);
                                busMaterialPackage100.setTopParentId(materialId);
                            } else {
                                busMaterialPackage100.setParentId(parentId);
                                busMaterialPackage100.setTopParentId(parentId);
                            }
                        }
                        busMaterial.setParentId(busMaterialPackage100.getParentId());
                        busMaterialList.add(busMaterial);
                        busMaterialPackage100.setPackageNo(packageNo);
                        busMaterialPackage100.setPackageName(packageName);
                        busMaterialPackage100.setMajorName(majorName);
                        busMaterialPackage100.setMajorCode(majorCode);
                        busMaterialPackage100.setServiceCode(serviceCode);
                        busMaterialPackage100.setServiceWbsCode(serviceWbsCode);
                        busMaterialPackage100.setSubjectName(subjectName);
                        busMaterialPackage100.setLevelNo(levelNo);
                        busMaterialPackage100.setMaterialArea(materialArea);
                        busMaterialPackage100.setMaterialUse(materialUse);
                        busMaterialPackage100.setCostQuantity100(costQuantity100);
                        busMaterialPackage100.setPackageDesc(packageDesc);
                        busMaterialPackage100.setContractDesc(contractDesc);
                        busMaterialPackage100.setSupplierNum1(supplierNum1);
                        busMaterialPackage100.setSupplierNum2(supplierNum2);
                        busMaterialPackage100.setSupplierNum3(supplierNum3);
                        busMaterialPackage100.setSupplierNum4(supplierNum4);
                        busMaterialPackage100.setSupplierNum5(supplierNum5);
                        busMaterialPackage100.setSupplierNum6(supplierNum6);
                        busMaterialPackage100.setSupplierNum7(supplierNum7);
                        busMaterialPackage100.setSupplierNum8(supplierNum8);
                        busMaterialPackage100.setSupplierNum9(supplierNum9);
                        busMaterialPackage100.setSupplierNum10(supplierNum10);
                        busMaterialPackage100.setStatus(1);
                        busMaterialPackage100.setVersionStatus(0);
                        busMaterialPackage100.setPlanType(type);
                        busMaterialPackage100.setVersionId(busVersion.getVersionId());
                        busMaterialPackage100List.add(busMaterialPackage100);
                    }
                }
            }
            if (busMaterialList.size() > 0) {
                busMaterialPackage100Service.saveBatch(busMaterialPackage100List);
                busMaterialService.saveBatch(busMaterialList);
                busProject.setVersionId(busVersion.getVersionId());
                busProjectService.updateById(busProject);
                return ResultBody.ok("导入成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultBody.failed("导入失败");
    }

    @Override
    public ResultBody getPackagePageList(Map params) {
        Long projectId = TypeUtils.castToLong(params.get("projectId"));
        BusProject busProject = busProjectService.getById(projectId);
        if (FlymeUtils.isEmpty(busProject)) {
            return ResultBody.ok(new Page());
        }
        Long versionId = busProject.getVersionpackageId();
        BusVersion busVersion = busVersionService.getById(versionId);
        if (FlymeUtils.isEmpty(busVersion)) {
            return ResultBody.ok(new Page());
        }
        Integer bigVersion = FlymeUtils.getInteger(busVersion.getBigVersion(), 0);
        int version = bigVersion / 100;
        if (version == 1) {
            return pageList(params);
        }
        if (version == 2) {
            return busMaterialPackage200Service.pageList(params);
        }
        return ResultBody.ok(new Page());
    }

    @Override
    public List<BusMaterialPackage100> getByGroup4Field(Map params) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("projectId", params.get("projectId"));
        cq.eq("parentId", 0);
        cq.groupBy("projectId", "packageNo", "majorCode", "topParentId");
        return list(cq);
    }

    @Override
    public List<BusMaterialPackage100> getByGroup3Field(Long projectId) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("projectId", projectId);
        cq.eq("parentId", 0);
        cq.gt("costQuantity100", 0);
        return list(cq);
    }

    @Override
    public EntityMap sumByField(Long projectId, String majorCode, String packageNo, Long topParentId) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect("COALESCE(SUM(costQuantity100),0) totalCostQuantity100", "COALESCE(SUM(costQuantity200),0) totalCostQuantity200", "COALESCE(SUM(supplierNum1),0) totalSupplierNum1");
        cq.addSelect("COALESCE(SUM(supplierNum2),0) totalSupplierNum2", "COALESCE(SUM(supplierNum3),0) totalSupplierNum3", "COALESCE(SUM(supplierNum4),0) totalSupplierNum4");
        cq.addSelect("COALESCE(SUM(supplierNum5),0) totalSupplierNum5", "COALESCE(SUM(supplierNum6),0) totalSupplierNum6", "COALESCE(SUM(supplierNum7),0) totalSupplierNum7");
        cq.addSelect("COALESCE(SUM(supplierNum8),0) totalSupplierNum8", "COALESCE(SUM(supplierNum9),0) totalSupplierNum9", "COALESCE(SUM(supplierNum10),0) totalSupplierNum10");
        cq.eq("projectId", projectId);
        cq.eq("majorCode", majorCode);
        cq.eq("packageNo", packageNo);
        cq.eq("topParentId", topParentId);
        return findOne(cq);
    }

    @Override
    public EntityMap sumSupplierNum(Long projectId, String majorCode, String packageNo, String SupplierNumField) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect("coalesce(SUM(" + SupplierNumField + "),0)totalSupplierNum");
        cq.eq("projectId", projectId);
        cq.eq("majorCode", majorCode);
        cq.eq("packageNo", packageNo);
        return findOne(cq);
    }

    @Override
    public int totalByProject(Long projectId) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("projectId", projectId);
        return count(cq);
    }

    @Override
    public int totalByProjectAndVersionStatus(Long projectId, Integer versionStatus) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("projectId", projectId);
        cq.eq("versionStatus", versionStatus);
        return count(cq);
    }


    @Override
    public ResultBody getSrmPms05Req(Map map) {
        OpenUser user = OpenHelper.getUser();
        String username = user.getUsername();
        Long projectId = FlymeUtils.getLong(map.get("projectId"));
        String majorCode = TypeUtils.castToString(map.get("majorCode"));
        String packageNo = TypeUtils.castToString(map.get("packageNo"));
        try {
            Boolean b = pmsOaUtil.updateMaterialBaseForPackageSingleNoSync(projectId, majorCode, packageNo, ApiConstants.VER_100, username);
            if (b) {
                if (ApiConstants.COMMON_RESULT_ZERO == syncSrmService.planCreate(projectId, majorCode, packageNo, ApiConstants.VER_100, username)) {
                    return ResultBody.ok(ApiConstants.OK_MSG_SRM05_01);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultBody.failed(e.getMessage());
        }
        return ResultBody.failed("调用失败");
    }

    @Override
    public ResultBody getSrmPms05ReqForApproval(Map map) {
        OpenUser user = OpenHelper.getUser();
        String username = user.getUsername();
        Long projectId = FlymeUtils.getLong(map.get("projectId"));
        String majorCode = TypeUtils.castToString(map.get("majorCode"));
        String packageNo = TypeUtils.castToString(map.get("packageNo"));
        int approval = syncOAService.approval(map, "", username, ApiConstants.BUSINESS_APPROVAL_FB_CONTACTS, projectId.toString());
        if (ApiConstants.APPROVAL_SUCCESS == approval) {
            return ResultBody.ok("OA审批提交成功");
        }
        return ResultBody.ok("OA审批提交失败");
    }

    @Override
    public List<EntityMap> selectVersionList(Map map) {
        String planType = (String) map.get("planType");
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.select(BusVersion.class, "versionId", "concat(bigVersion,'.',smallVerion) as versionNo");
        cq.eq("bmp.projectId", map.get("projectId"));
        cq.eq("bmp.majorCode", map.get("majorCode"));
        cq.eq("bmp.packageNo", map.get("packageNo"));
        cq.eq("bmp.planType", planType);
        cq.isNotNull("version.versionId");
        cq.createJoin(BusVersion.class).setMainField("versionId").setJoinField("versionId");
        cq.groupBy("bmp.versionId");
        return selectEntityMap(cq);
    }

    @Override
    public EntityMap getAllSupplierNum(Map map) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.addSelect("COALESCE(sum(supplierNum1),0) totalSupplierNum1,COALESCE(sum(supplierNum2),0) totalSupplierNum2");
        cq.addSelect("COALESCE(sum(supplierNum3),0) totalSupplierNum3,COALESCE(sum(supplierNum4),0) totalSupplierNum4");
        cq.addSelect("COALESCE(sum(supplierNum5),0) totalSupplierNum5,COALESCE(sum(supplierNum6),0) totalSupplierNum6");
        cq.addSelect("COALESCE(sum(supplierNum7),0) totalSupplierNum7,COALESCE(sum(supplierNum8),0) totalSupplierNum8");
        cq.addSelect("COALESCE(sum(supplierNum9),0) totalSupplierNum9,COALESCE(sum(supplierNum10),0) totalSupplierNum10");
        cq.eq("bmp.projectId", map.get("projectId"));
        cq.eq("bmp.majorCode", map.get("majorCode"));
        cq.eq("bmp.packageNo", map.get("packageNo"));
        return findOne(cq);
    }

    @Override
    public List<BusMaterialPackage100> selectBusMaterialPackage100List(Long projectId, String majorCode, String packageNo) {
        CriteriaQuery<BusMaterialPackage100> cq = new CriteriaQuery(BusMaterialPackage100.class);
        cq.eq("projectId", projectId);
        cq.eq("majorCode", majorCode);
        cq.eq("packageNo", packageNo);
        cq.eq("versionStatus", 0);
        return list(cq);
    }


    private BusVersion init200Version(Long projectId) {
        Long versionId = IdWorker.getId();
        BusVersion version = new BusVersion();
        version.setVersionId(versionId);
        version.setProjectId(projectId);
        version.setVersionType(2);
        version.setBigVersion("200");
        version.setSmallVerion("00");
        version.setState(1);//1正常 0锁定
        return version;
    }

    private BusVersion init100Version(Long projectId) {
        Long versionId = IdWorker.getId();
        BusVersion version = new BusVersion();
        version.setVersionId(versionId);
        version.setProjectId(projectId);
        version.setVersionType(2);
        version.setBigVersion("100");
        version.setSmallVerion("00");
        version.setState(1);//1正常 0锁定
        return version;
    }
}
